define(function(require, exports, module) {
	var $ = require("$");
	
	//require("button");
	
	require("bootstrap");
	//require("bootstrap_themeSea");
	var validate = require("jquery.validate");
	
	require("bootstrap.css");
	require("bootstrap-responsive.css");
	require("light-theme.css");
	
	var form_tpl = require("./form.tpl");
	var Widget = require("widget");
	//var Log = require("log");
	//require("../theme/default/css/form.css");
	var handlebars = require("handlebars");
	

	
	var Form = Widget.extend({
		handlebars : handlebars,
		// 初始化参数
		initCustAttr : function() {
			// 输入项初始化
			var attrs = this.get("attrs");
			
			// 是否显示Box-Content样式（边框）
			attrs.useBoxContent = attrs.useBoxContent == null ? true : attrs.useBoxContent;
		},
		template : form_tpl,
		//校验
		validate:function(){
			var that = this;
			var items = this.get("items");
			for(var i=0;i<items.length;i++){
				var item = items[i];
				if(item.required){
					if (item.type == "daterange") {
						var beginName = item.beginName;
						var beginDate = that.element.find("[name="+beginName+"]").val();
						var endName = item.endName;
						var endDate = that.element.find("[name="+endName+"]").val();

						if (beginDate == "" || endDate == "") {
							alert("开始和结束" + item.label + "必填！");
							return false;
						}
						if (beginDate > endDate) {
							alert('结束日期必须大于或者等于开始日期');
							return false;
						}
					} else {
						var name = item.name;
						// 常规字符型输入框
						if (name) {
							var value = that.element.find("[name="+name+"]").val();
							if(value ==""){
								alert(item.label+"必填！");
								return false;
							}
						}
					}
				}
			}
			return true;
		}

	});
	module.exports = Form;
});